#include "../include//GoldenFinger.h"


using namespace std;

//计算金手指的长和宽 
void GoldenFinger::getLengthandWidth(const std::vector<Line>& OuterContour) {
	double tempDistance;
	Line tempLine;
	vector<double> SegmentsDist;

	for (int i = 0; i < OuterContour.size(); ++i) {
		tempLine = OuterContour[i];
		if (this->shapeType == 0) {
			if (tempLine.State == 0 && this->fingerLength == 0) {//线段
				this->fingerLength = tempLine.norm(tempLine.Pt2 - tempLine.Pt1);
				//continue;
			}
			if (tempLine.State == 1 && this->fingerWidth == 0) {
				this->fingerWidth = tempLine.norm(tempLine.Pt2 - tempLine.Pt1);
				//continue;
			}
		}
		else {
			tempDistance = getLength(tempLine);
			SegmentsDist.emplace_back(tempDistance);
		}
	}

	if (this->shapeType == 1) {
		double minDistance, maxDistance;

		//Init
		minDistance = maxDistance = SegmentsDist[0];

		for (int i = 1; i < SegmentsDist.size(); ++i) {
			tempDistance = SegmentsDist[i];
			if (tempDistance < minDistance) {
				minDistance = tempDistance;
			}
			else if(tempDistance > maxDistance) {
				maxDistance = tempDistance;
			}
		}

		this->fingerLength = maxDistance;
		this->fingerWidth = minDistance;

	}
}

double GoldenFinger::getRotation() const
{
	return rotation;
}

double GoldenFinger::getLength(const Line& a) {    //向量的模，传入参数Line
	Point OneP = a.Pt2;
	Point TwoP = a.Pt1;

	Point p = OneP - TwoP;
	return sqrt(p.x * p.x + p.y * p.y);
}


void GoldenFinger::setfingerOuter(const std::vector<Line>& OuterContour) {
	this->fingerOuter.clear();  //清空之前的
	for (int i = 0; i < OuterContour.size(); ++i) {
		this->fingerOuter.emplace_back(OuterContour[i]);
	}
}

void GoldenFinger::setGoldWire(const Line& goldLine) {
	this->goldWire = goldLine;
}

void GoldenFinger::setOrientation(int direction) {
	this->fingerOrientation = direction;
}

void GoldenFinger::setSnapType(int snapType) {
	this->snapType = snapType;
}

void GoldenFinger::setShapeType(int shapeType) {
	this->shapeType = shapeType;
}

void GoldenFinger::setDirty(int dirtyValue) {
	this->dirty = dirtyValue;
}

void GoldenFinger::setTag(int tagValue) {
	this->tag = tagValue;
}

void GoldenFinger::setFingerPadStack(const FingerPadStack& padStack)
{
	this->fingerPadStack = padStack;
}
